# 有一个细节错误
class Solution:
    def intersection(self, nums1: List[int], nums2: List[int]) -> List[int]:
        nums1.sort()
        nums2.sort()
        key1, key2 = 0, 0
        ans = []
        while key1 < len(nums1) and key2 < len(nums2):
            if nums1[key1] == nums2[key2]:
                if nums1[key1] not in ans:  #这里可能会无休止的执行下去
                    ans.append(nums1[key1])
                    key1 += 1
                    key2 += 1
            elif nums1[key1] > nums2[key2]:
                key2 += 1
            else:
                key1 += 1
        return ans

# 修好后的代码
class Solution:
    def intersection(self, nums1: List[int], nums2: List[int]) -> List[int]:
        nums1.sort()
        nums2.sort()
        key1, key2 = 0, 0
        ans = []
        while key1 < len(nums1) and key2 < len(nums2):
            if nums1[key1] == nums2[key2]:
                tmp = nums1[key1]
                key1 += 1
                key2 += 1
                if tmp not in ans:
                    ans.append(tmp)
            elif nums1[key1] > nums2[key2]:
                key2 += 1
            else:
                key1 += 1
        return ans